<?php

namespace App\Model\Common;

class Slider extends Common
{
    public static function listDataFormat($list, $opt = [])
    {
        $data = [];
        foreach ($list as $li) {
            $data[$li['type']][] = $li;
        }

        return $data;
    }

    public static function getSliders($type, $opt = [])
    {
        $sliders = cache('slider:all');
        if (empty($menus) || (!empty($opt['no_cache']) && true === $opt['no_cache'])) {
            $sliders = self::where('status', 1)->orderBy('rank', 'desc')->get();
            cache(['slider:all' => $sliders], 5);
        }
        $sliders = self::listDataFormat($sliders);

        if ($type) {
            return $sliders[$type];
        } else {
            return $sliders;
        }
    }

    public function refreshCache($m, $mode = 'update')
    {
        $this->getSliders(null, ['no_cache' => true]);

        return true;
    }
}
